<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>区域管理编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${ctx}/js/jsp/yd/logic/freigHtageTypeData.js"></script>
<script type="text/javascript">
var basic_Url="${ctx}/yd/basic/bom";
var grid;
// var ItemStateList = freigHtageTypeData.Rows;
$(function(){
	
// 	 $("#kdgs").change(function(){ 
// 			$("#creategsname").val($("#kdgs").find("option:selected").text());
// 			$("#creategscode").val($("#kdgs").val());
// 		}); 
	 
	
	var griddata ={};
	grid = $("#table1").ligerGrid({
        columns: [
				  { display: 'id', name: 'id', width: 1,hide:1 },
				  { display: '编码', name: 'rawcode', width: 1,hide:1 },
                  { display: '物料名称', name: 'rawname', width: 180 },
                  { display: '规格型号', name: 'model', width: 120 },
                  { display: '基本单位', name: 'unit', width: 120},
                  { display: '', name: 'basicUnit', width: 120,hide:true},
                  { display: '用量', name: 'dosage', width: 120,editor: { type: 'float'},render:function(item){
                   	  return item.dosage;
                  }},
                  { display: '基本用量', name: 'basicDosage', width: 120,editor: { type: 'float'},render:function(item){
                   	  return item.basicDosage;
                  }},
                  { display: '损益率', name: 'ullage', width: 120,editor: { type: 'float'},render:function(item){
                   	  return item.ullage;
                  }},
                  ],
                  enabledEdit: true,
                  usePager: true,pageSize:1000,pageSizeOptions:[1000],
                  data : griddata,
                  width: "100%", height:200, checkbox: true,
                  toolbar: { items: [
                                     { text: '添加物料', click: ItemWindow, icon: 'add' },
                                     { line: true },
                                     { text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
                                     ]
                                     }
                  });
	
	
	$("#pageloading").hide();

	$("#inputForm").validate({			   
	onsubmit: true,
	 /*执行ajaxsubmit  */ 
    submitHandler: function(editform) {
        try{			    		
            url =  basic_Url+"/save.do";
            var api = frameElement.api;
        	var W = api.opener;
        	getReturnMessage(basic_Url+"/save.do","inputForm",W.searchAP);
        }catch(e){alert(e)}
    }
	});

	
	if('${bbd.billstatus}' == ""){
		$("#save1").hide();//禁用保存按钮
		$("#save2").hide();//禁用保存按钮
		$("#bohui").hide();
	}
	else if('${bbd.billstatus}' == "0" ){
		$("#save").hide();//禁用保存按钮
		$("#save2").hide();//禁用保存按钮
		$("#save3").hide();//禁用保存按钮
		$("#bohui").hide();
	}
	else if('${bbd.billstatus}' == "1" ){
		$("#save1").hide();//禁用保存按钮
		$("#save").hide();//禁用保存按钮
		$("input[type!='hidden']").attr("disabled","disabled");
		$("select").attr("disabled","disabled");//禁用SELECT标签
		$("textarea").attr("disabled","disabled");//禁用TEXTAREA标签
	}
	else if('${bbd.billstatus}' == "2"){
		$("#save1").hide();//禁用保存按钮
		$("#save2").hide();//禁用保存按钮
		$("#save").hide();//禁用保存按钮
		$("input[type!='hidden']").attr("disabled","disabled");
		$("select").attr("disabled","disabled");//禁用SELECT标签
		$("textarea").attr("disabled","disabled");//禁用TEXTAREA标签
	}
	else{
		$("#save").hide();//禁用保存按钮
		$("#save1").hide();//禁用保存按钮
		$("#save2").hide();//禁用保存按钮
		$("#bohui").hide();
		$("input[type!='hidden']").attr("disabled","disabled");
		$("select").attr("disabled","disabled");//禁用SELECT标签
		$("textarea").attr("disabled","disabled");//禁用TEXTAREA标签
	}
	
	if ('${flag}' == 'ADD'){
		
	}
	
	<c:forEach items='${bomRal}' var='item'>
    	var manager = $("#table1").ligerGetGridManager();
    	manager.addRow({
    		id : "${item.id}",
    		rawcode : "${item.rawcode}",
    		rawname : "${item.rawname}",
    		model : "${item.model}",
    		unit : "${item.unit}",
    		basicUnit : "${item.basicUnit}",
    		dosage : "${item.dosage}",
    		basicDosage : "${item.basicDosage}",
    		ullage : "${item.ullage}",
    		remark : "${item.remark}",
		});
		</c:forEach>
		
	})

	function ItemWindow() {
		if ('${xx}' == 1){
			getDG().dialog(
					{
						title : '选择材料',
						width : 650,
						height : 350,
						content : 'url:' + sys_context+ '/public/windowalert/itemmanager.do',//
						lock : true,
						max : true,
						min : true,
						ok : function() {
							var getSelectedHub = this.content.getSelected();
							var manager = $("#table1").ligerGetGridManager();
							if (getSelectedHub != null) {
								 $(getSelectedHub).each(function ()
								            {
									                manager.addRow({
									                rawcode: this.code,
									                rawname: this.name,
									                model : this.spec,
									                unit: this.unit,
									                basicUnit:this.unitMeasurement
								                });
								 });	
								this.content.Close();
							}
							return false;
						},
						cancelVal : '关闭',
						cancel : true
					}).zindex();
		}
	}
	


	function deleteRow()
	{ 
		grid.deleteSelectedRow();
	}
	
	function submitForm(param) {
		//设置ajax全局同步

		var data = grid.getData();
		var dl = grid.getDeleted();
		if (data.length == 0) {
			$.dialog.alert("请选择申请物料");
			return false;
		}
		var ba = true;
		if (data != null) {
			var i = 0;
			$(data).each(function() {
				i++;
				if (this.dosage == ""||this.dosage==null) {
					$.dialog.alert("您第" + i + "行的用量没有填写!");
					ba = false;
					return false;
				}
				if (this.basicDosage == ""||this.basicDosage==null) {
					ba = false;
					$.dialog.alert("您第" + i + "行的基本用量没有填写!");
					return false;
				}
				if (this.ullage == ""||this.ullage==null) {
					ba = false;
					$.dialog.alert("您第" + i + "行的损益率没有填写!");
					return false;
				}
				if (this.dosage<0) {
					$.dialog.alert("您第" + i + "行的用量不能小于0");
					ba = false;
					return false;
				}
				if (this.basicDosage<0) {
					$.dialog.alert("您第" + i + "行的基本用量不能小于0");
					ba = false;
					return false;
				}
				if (this.ullage<0) {
					ba = false;
					$.dialog.alert("您第" + i + "行的损益率不能小于0");
					return false;
				}
			});
		}
		jQuery.ajaxSettings.async = false;
		if (ba) {
			$("#type").val(param);
			$("#itemdata").val(JSON.stringify(data));
			$("#itemdelete").val(JSON.stringify(dl));
			$("#inputForm").submit();
		}
	}
	function bhcheck(){
		if($("#id").val()==""){
			$.dialog.alert("没有提交无法驳回");
			return false;
		}
		$.ajax({
	      	url: "${ctx}/yd/basic/bom/updateState.do",
	      	global: false,
	      	type: "POST",
	     	dataType: "json",
	      	data: ({
	    	  	rows : $("#id").val(),checktype:"0"
	      	}),		     
	      	success: function(msg){
	    	  	if(msg.msg=="SUCCESS"){
	    		  	$.dialog.alert("驳回成功");
	    	  	}
	    	  	if(msg.msg=="ERROR"){
	    		  	$.dialog.alert("驳回失败");
	    	  	}
	    	  	CloseDialog();
	    	  	var api = frameElement.api;
	         	var W = api.opener;
	            W.searchAP();
	   		}
		});
	}
</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${bbd.id}"/>
<input type="hidden" id="itemdata" name="itemdata" value=""/>
<input type="hidden" id="itemdelete" name="itemdelete" value=""/>
<input type="hidden" id="type" name="type" value=""/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
				<tr>
                    <td nowrap>类型名称:</td>
   		                 <td>
   		                <input type="text" id=turnoffName name="turnoffName" class="required"  value="${bbd.turnoffName}" />
   		                 </td>
   		                  <td nowrap>类型父类:</td>
   		                  <td>
   		                  <c:choose>
   		                  	<c:when test="${empty bbd.parentTurnoffName}">
   		                  		<input type="text" id="parent" name="parent" readonly="readonly" value="${bname}" />
   		                  	</c:when>
   		                  	<c:otherwise>
   		                  		<input type="text" id="parent" name="parent" readonly="readonly" value="${bbd.parentTurnoffName}" />
   		                  	</c:otherwise>
   		                  </c:choose>
   		                 	<input type="hidden" id="parentTurnoffName" name="parentTurnoffName" value="${bbd.parentTurnoffName}" />
   		                 	<input type="hidden" id="parentid" name="parentid" value="${bbd.parentid}" />
   		                 	<input type="hidden" id="parentadd" name="parentadd" value="${bid}" />
   		                 	<input type="hidden" id="parentnameadd" name="parentnameadd" value="${bname}" />
   		                 </td>
   		           </tr>
   		           <tr>
                    <td nowrap>编码:</td>
   		                 <td>
   		                <input type="text" id=turnoffCode name="turnoffCode" class="required"  value="${bbd.turnoffCode}" />
   		                 </td>
   		                 <td nowrap>规格型号:</td>
   		                 <td>
   		                <input type="text" id=turnoffNameSpec name="turnoffNameSpec" class="required"  value="${bbd.turnoffNameSpec}" />
   		                 </td>
   		           </tr>
   		           <tr>
                    <td nowrap>物料属性:</td>
   		                 <td>
   		                <input type="text" id=attribute name="attribute" class="required" value="${bbd.attribute}" />
   		                 </td>
   		                 <td nowrap>单位:</td>
   		                 <td>
   		                <input type="text" id=turnoffNameUnit name="turnoffNameUnit" class="required"  value="${bbd.turnoffNameUnit}" />
   		                 </td>
   		           </tr>
   		           <tr>
                    <td nowrap>使用状态:</td>
   		                 <td>
   		                 <select id="useStatus"  name="useStatus">
   		                 	<option value="0">未使用</option>
   		                 	<option value="1">使用</option>
   		                 </select>
   		                 <script type="text/javascript">
   		                 	$(function(){
   		                 		$("#useStatus").val('${bbd.useStatus}');
   		                 	});
						</script>
   		                 </td>
   		           </tr>
                </table>
                <div id="table1"> </div> 
         </div>
         <div class="formBar">
	        <ul>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save" onclick="submitForm(0)">保存草稿</button></div></div></li>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save1" onclick="submitForm(1)">直接提交</button></div></div></li>
		       <webres:displaycontroller elementId="BOM_ZG_CHEECK_PH" description="BOM申请驳回">
		       		<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="bohui" onclick="bhcheck()">驳回</button></div></div></li>
		      	</webres:displaycontroller>
		       <webres:displaycontroller elementId="BOM_YJ_CHEECK" description="一级审核">
		       			<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save2" onclick="submitForm(2)">一级审核</button></div></div></li>
		      		</webres:displaycontroller>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>    
    </div>
</form>
</body>
</html>
